var table;
function init() {
	initData();
}
function initData() {
	var loading = layer.load(1, {
	  shade: [0.5,'#fff'] //0.1透明度的白色背景
	});
	$.getJSON("/rest/protectRiskAssment/getAlarmMsgByIds/"+params.ids, function(result) {
		layer.close(loading);
		loadTable(result);
	});
}
function loadTable(result) {
	if (table) {
		table.getTable().destroy();
	}
	var columns = ['序号','告警级别','告警类型','时间','内容','详情 '];
	var opt = MyTable.getDefaultOptions();
	opt.paging = false;
	opt.searching = true;
	opt.scrollY = 500;
	table = new MyTable("datatable", columns, opt);
	var data = [];
	for(var i in result){
		/**
		 * 根据type，将参数加到btn中
		 */
		var d = result[i];
		var opt = '<button onclick="gotoDetail(this)" data-msgType="'+d.msgType+'" data-id="'+d.source+'" class="btn btn-primary fa fa-search"/>';
		data.push([Number(i)+1,d.msgLevel,d.msgTypeText,DateUtil.locale(d.createTime),d.content,opt]);
	}
	table.setDataSet(data).show();
}
function query(){
	initData();	
}
function gotoDetail(ele) {
	var fra = document.createElement("iframe");
	fra.style = "background:transparent;border:0;";
	fra.width = "100%";
	fra.id = "iframe";
	fra.height = "650px";
	var id = $(ele).attr('data-id');
	var msgType = $(ele).attr('data-msgType');
	var url = getUrl(msgType,id);
	fra.src = url;
	document.body.appendChild(fra);
	$('#tableDiv').css('display', 'none');
};
function getUrl(msgType,sourceId){
	var url = '';
	switch (msgType) {
	case "hlyc":
		url = "/ui/map/dialog/riskAlarmDialog/protectDeviceException.xhtml?oId="
						+ sourceId+"&showBackBtn=true";
		break;
	case "tdyc_single":
	case "tdyc_double":
		url = "/ui/map/dialog/riskAlarmDialog/protectChannelException.xhtml?oId="
						+ sourceId+"&showBackBtn=true";
		break;
	}
	return url;
}
function backFromChild() {
	document.body.removeChild(document.getElementById("iframe"));
	$('#tableDiv').css('display', 'block');
	table.getTable().draw();
}